package com.audio.handler;


import com.audio.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 捕捉业务异常
     * @param ex
     * @return
     */
    @ExceptionHandler
    public Result exceptionHandler(Exception ex) {
        Throwable cause = ex.getCause();
        if (cause != null) {
            log.error("根本异常信息：{}", cause.getMessage());
            return Result.error(cause.getMessage());
        }
        log.error("异常信息：{}", ex.toString());
        return Result.error(ex.getMessage());
    }

}
